# 假设有验证集加载器 val_loader
model.eval()
with torch.no_grad():
    correct = 0
    total = 0
    for images, labels in val_loader:
        images, labels = images.to(device), labels.to(device)
        outputs = model(images)
        _, predicted = torch.max(outputs.data, 1)
        total += labels.size(0)
        correct += (predicted == labels).sum().item()

    print(f'Accuracy of the model on the validation set: {100 * correct / total}%')

# 保存模型
torch.save(model.state_dict(), 'model_weights.pth')
